import Fly from 'flyio/dist/npm/fly'
import env from '../config/env'
// 新建request对象
const request = new Fly()

// 请求超时时间
request.config.timeout = 60 * 1000000

// 统一请求前辍
request.config.baseURL = env.TM_PREFIX
// 请求拦截
request.interceptors.request.use((request) => {
})
// 返回拦截
request.interceptors.response.use(
    (response, promise) => {
        // 返回数据
        return promise.resolve(JSON.parse(response.data))
    },
    (err, promise) => {
        alert(JSON.stringify(err))
        return promise.resolve()
    }
)

/**
 * 获取授权token
 * @param param
 * @returns {*}
 */
export const getToken = (param) => {
    return request.get(`/DBUToolPGSQL/tokenInfo/getToken.do`, Object.assign({ email: sessionStorage.getItem('email') }, param))
}

/**
 * 获取pt下的产品
 * @param param
 * @returns {*}
 */
export const getDictionary = (param) => {
    return request.get(`/DBUToolPGSQL/dictionary/getFilterData.do?token=${param.tokenString}&monthId=${param.monthId}&employeeCode=${param.employeeCode}&filterType=${param.filterType}`)
}
/**
 * 获取pt-dm下的产品
 * @param param
 * @returns {*}
 */
export const getDictionaryDm = (param) => {
    return request.get(`/DBUToolPGSQL/dictionary/getFilterData.do?token=${param.tokenString}&monthId=${param.monthId}&filterType=${param.filterType}`)
}
/**
 * 获取筛选框
 * @param param
 * @returns {*}
 */
export const getFilterData = (param) => {
    return request.get(`/DBUToolPGSQL/dictionary/getFilterData.do?token=${param.tokenString}&monthId=${param.monthId}&employeeCode=${param.employeeCode}&filterType=${param.filterType}&product=${param.product}`)
}

/**
 * 获取进度管理上方(Dashboard)
 * @param param
 * @returns {*}
 */
export const getManageDashborad = (param) => {
    return request.get(`/DBUToolPGSQL/plan/getManageDashborad.do?token=${param.tokenString}&monthId=${param.monthId}&quarterId=${param.quarterId}&territoryCd=${param.territoryCd}`,)
}

/**
 * 获取list
 * @param param
 * @returns {*}
 */
export const getProgreessOfManageData = (param) => {
    return request.get(`/DBUToolPGSQL/plan/getProgreessOfManageData.do?token=${param.tokenString}&monthId=${param.monthId}&quarterId=${param.quarterId}&productCode=${param.productCode}&isSuccess=${param.isSuccess}&isFocus=${param.isFocus}&potentialCode=${param.potentialCode}&newStatus=${param.newStatus}&hospitalCode=${param.hospitalCode}&insDepartNM=${param.insDepartNM}&hospitalName=${param.hospitalName}&territoryCd=${param.territoryCd}&FactionsCd=${param.FactionsCd}`)
}

/**
 * 进度管理包含饼图DM
 * @param param
 * @returns {*}
 */
export const getProgreessOfManageDataOnDM = (param) => {
    return request.get(`/DBUToolPGSQL/plan/getProgreessOfManageDataOnDM.do?territoryCd=${param.territoryCd}&monthId=${param.monthId}&quarterId=${param.quarterId}`)
}

/**
 * 进度管理包含饼图RM
 * @param param
 * @returns {*}
 */
export const getProgreessOfManageDataOnRM = (param) => {
    return request.get(`/DBUToolPGSQL/plan/getProgreessOfManageDataOnRM.do?territoryCd=${param.territoryCd}&monthId=${param.monthId}&quarterId=${param.quarterId}`)
}

/**
 * 获取客户分型列表
 * @param param
 * @returns {*}
 */
export const getSubByRole = (param) => {
    return request.get(`/DBUToolPGSQL/customerSegment/getSubByRole.do`,param)
}
